////////////////////////////////////////////////////////////////////////////////
// Filename: positionclass.cpp
////////////////////////////////////////////////////////////////////////////////
#include "positionclass.h"


PositionClass::PositionClass()
{
	m_frameTime = 0.0f;
	m_rotationY = 0.0f;
	m_leftTurnSpeed  = 0.0f;
	m_rightTurnSpeed = 0.0f;
	m_rotationZ = 0.0f;
	m_upTurnSpeed  = 0.0f;
	m_downTurnSpeed = 0.0f;
	m_forwardSpeed = 0.0f;
	m_backwardSpeed = 0.0f;
	m_leftSpeed = 0.0f;
	m_rightSpeed = 0.0f;
	m_speedmultiplier = 10.0f;
}


PositionClass::PositionClass(const PositionClass& other)
{
}


PositionClass::~PositionClass()
{
}


void PositionClass::SetFrameTime(float time)
{
	m_frameTime = time;
	return;
}


void PositionClass::GetYRotation(float& y)
{
	y = m_rotationY;
	return;
}
void PositionClass::GetZRotation(float& z)
{
	z = m_rotationZ;
	return;
}
void PositionClass::GetMovementForward(float& f)
{
	f = m_speedmultiplier * (m_forwardSpeed + m_backwardSpeed);
	return;
}
void PositionClass::GetMovementRight(float& r)
{
	r = m_speedmultiplier * (m_rightSpeed + m_leftSpeed);
	return;
}

void PositionClass::TurnLeft(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns left.  If not slow down the turn speed.
	if(keydown)
	{
		m_leftTurnSpeed += m_frameTime * 0.01f;

		if(m_leftTurnSpeed > (m_frameTime * 0.15f))
		{
			m_leftTurnSpeed = m_frameTime * 0.15f;
		}
	}
	else
	{
		m_leftTurnSpeed -= m_frameTime* 0.005f;

		if(m_leftTurnSpeed < 0.0f)
		{
			m_leftTurnSpeed = 0.0f;
		}
	}

	// Update the rotation using the turning speed.
	m_rotationY -= m_leftTurnSpeed;
	if(m_rotationY < 0.0f)
	{
		m_rotationY += 360.0f;
	}

	return;
}


void PositionClass::TurnRight(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_rightTurnSpeed += m_frameTime * 0.01f;

		if(m_rightTurnSpeed > (m_frameTime * 0.15f))
		{
			m_rightTurnSpeed = m_frameTime * 0.15f;
		}
	}
	else
	{
		m_rightTurnSpeed -= m_frameTime* 0.005f;

		if(m_rightTurnSpeed < 0.0f)
		{
			m_rightTurnSpeed = 0.0f;
		}
	}

	// Update the rotation using the turning speed.
	m_rotationY += m_rightTurnSpeed;
	if(m_rotationY > 360.0f)
	{
		m_rotationY -= 360.0f;
	}

	return;
}

void PositionClass::TurnUp(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns up.  If not slow down the turn speed.
	if(keydown)
	{
		m_upTurnSpeed += m_frameTime * 0.01f;

		if(m_upTurnSpeed > (m_frameTime * 0.15f))
		{
			m_upTurnSpeed = m_frameTime * 0.15f;
		}
	}
	else
	{
		m_upTurnSpeed -= m_frameTime* 0.005f;

		if(m_upTurnSpeed < 0.0f)
		{
			m_upTurnSpeed = 0.0f;
		}
	}

	// Update the rotation using the turning speed.
	m_rotationZ -= m_upTurnSpeed;
	if(m_rotationZ < 0.0f)
	{
		m_rotationZ += 360.0f;
	}

	return;
}


void PositionClass::TurnDown(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_downTurnSpeed += m_frameTime * 0.01f;

		if(m_downTurnSpeed > (m_frameTime * 0.15f))
		{
			m_downTurnSpeed = m_frameTime * 0.15f;
		}
	}
	else
	{
		m_downTurnSpeed -= m_frameTime* 0.005f;

		if(m_downTurnSpeed < 0.0f)
		{
			m_downTurnSpeed = 0.0f;
		}
	}

	// Update the rotation using the turning speed.
	m_rotationZ += m_downTurnSpeed;
	if(m_rotationZ > 360.0f)
	{
		m_rotationZ -= 360.0f;
	}

	return;
}
void PositionClass::MoveForward(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_forwardSpeed += m_frameTime * 0.0001f;

		if(m_forwardSpeed > (m_frameTime * 0.001f))
		{
			m_forwardSpeed = m_frameTime * 0.001f;
		}
	}
	else
	{
		m_forwardSpeed -= m_frameTime* 0.0005f;

		if(m_forwardSpeed < 0.0f)
		{
			m_forwardSpeed = 0.0f;
		}
	}
	return;
}
void PositionClass::MoveBackward(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_backwardSpeed -= m_frameTime * 0.0001f;

		if(m_backwardSpeed < (-m_frameTime * 0.001f))
		{
			m_backwardSpeed = -m_frameTime * 0.001f;
		}
	}
	else
	{
		m_backwardSpeed += m_frameTime* 0.0005f;

		if(m_backwardSpeed > 0.0f)
		{
			m_backwardSpeed = 0.0f;
		}
	}
	return;
}
void PositionClass::MoveRight(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_rightSpeed += m_frameTime * 0.0001f;

		if(m_rightSpeed > (m_frameTime * 0.001f))
		{
			m_rightSpeed = m_frameTime * 0.001f;
		}
	}
	else
	{
		m_rightSpeed -= m_frameTime* 0.0005f;

		if(m_rightSpeed < 0.0f)
		{
			m_rightSpeed = 0.0f;
		}
	}
	return;
}
void PositionClass::MoveLeft(bool keydown)
{
	// If the key is pressed increase the speed at which the camera turns right.  If not slow down the turn speed.
	if(keydown)
	{
		m_leftSpeed -= m_frameTime * 0.0001f;

		if(m_leftSpeed < (-m_frameTime * 0.001f))
		{
			m_leftSpeed = -m_frameTime * 0.001f;
		}
	}
	else
	{
		m_leftSpeed += m_frameTime* 0.0005f;

		if(m_leftSpeed > 0.0f)
		{
			m_leftSpeed = 0.0f;
		}
	}
	return;
}